<template>
    <div>
        <van-form @submit="onSubmit">
            <van-field
            v-model="editeData.editeVal"
            :name="editeData.editeKey"
            :label="editeData.editeName"
            :rules="[{ required: true}]"
            />
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    修改
                </van-button>
            </div>
        </van-form>
    </div>
</template>

<style scoped>
</style>

<script setup>
import { useRouter,useRoute } from "vue-router";
import {ref} from "vue"
import Myaxios from "../plugins/MyAxios";

const router = useRouter()
const route = useRoute()
const editeData = ref({
    id: route.query.id,
    editeKey: route.query.editeKey,
    editeVal: route.query.editeVal,
    editeName: route.query.editeName,
});
const onSubmit = async (value) => {
    const res = await Myaxios.post("/update",{
        id: editeData.value.id,
        [editeData.value.editeKey]: editeData.value.editeVal
    })
    if(res.data.code === 200){
        router.replace({
            path: '/user',
        });
    }
};

</script>